package com.group.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.group.model.*;

@Repository
public interface TickerDao {

	public List<Ticker> queryTicker(@Param("key") String key, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryTickerCount(@Param("key") String key);

	public List<TickerShareUrlLog> queryTickerShareUrlLog(@Param("tickerShareUrlId") Long tickerShareUrlId, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryTickerShareUrlLogCount(@Param("tickerShareUrlId") Long tickerShareUrlId);

	public List<TickerShareUrl> queryTickerShareUrl(@Param("start") Integer start, @Param("limit") Integer limit);

	public int queryTickerShareUrlCount();

	public List<UserTickerLog> queryUserTickerLog(@Param("userId") Long userId, @Param("cid") String cid, @Param("reason") String reason, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryUserTickerLogCount(@Param("userId") Long userId, @Param("cid") String cid, @Param("reason") String reason);

	@Update("update TickerShareUrl t set t.receive = t.receive + #{arg1} where t.id = #{arg0}")
	public void updateTickerShareUrl(Long id, double ticker);

	@Select("select count(*) from friendsharelog l where l.friendShareId = #{arg0}")
	public int countShareTimes(Long friendShareId);

	@Select("select count(*) from friendsharelog l where l.userId = #{arg0}")
	public int countHelpTimes(Long userId);

	@Select("select ifnull(sum(num),0) from friendsharelog l where l.friendShareId = #{arg0}")
	public double countShareAmount(Long friendShareId);

	@Select("select * from exchangecandles b where b.baseAsset = #{cid} and b.quoteAsset = #{cid2} and b.timeFrame = #{frame} and b.exchange = #{exchange} order by b.id desc limit #{start},#{limit}")
	public List<ExchangeCandles> queryCandles(@Param("cid") String cid, @Param("cid2") String cid2, @Param("frame") String frame, @Param("exchange") String exchange, @Param("start") Integer start, @Param("limit") Integer limit);

	/**
	 * 查询成交记录
	 *
	 * @param cid
	 * @param cid2
	 * @param exchange
	 * @param start
	 * @param limit
	 * @return
	 */
	public List<ExchangeTrades> queryExchangeTrades(@Param("cid") String cid, @Param("cid2") String cid2, @Param("exchange") String exchange, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryExchangeTradesCount(@Param("cid") String cid, @Param("cid2") String cid2, @Param("exchange") String exchange);

	/**
	 * 行情搜索
	 *
	 * @param cid
	 * @param cid2
	 * @param exchange
	 * @param key
	 * @param start
	 * @param limit
	 * @return
	 */
	public List<TickerPrice> queryTickerPrice(@Param("cid") String cid, @Param("cid2") String cid2, @Param("exchange") String exchange, @Param("key") String key, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryTickerPriceCount(@Param("cid") String cid, @Param("cid2") String cid2, @Param("exchange") String exchange, @Param("key") String key);

	/**
	 * 查询用户收藏的行情
	 *
	 * @param userId
	 * @param start
	 * @param limit
	 * @return
	 */
	public List<TickerPrice> queryMyTickerPrice(@Param("userId") Long userId, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryMyTickerPriceCount(@Param("userId") Long userId);

	/**
	 * 查询账户余额
	 *
	 * @param cid
	 * @param start
	 * @param limit
	 * @return
	 */
	public List<AccountBalance> queryAccountBalance(@Param("cid") String cid, @Param("dateStr") String dateStr, @Param("start") Integer start, @Param("limit") Integer limit);

	public List<LongHuBang> queryLongHuBang(@Param("exchange") String exchange);

	/**
	 * 查询提现记录
	 *
	 * @param start
	 * @param limit
	 * @return
	 */
	public List<UserTickerLog> queryBackUserTickerLog(@Param("reason") String reason, @Param("userId") Long userId, @Param("start") Integer start, @Param("limit") Integer limit,@Param("userName") String userName,@Param("date") String date);

	public int queryBackUserTickerLogCount(@Param("reason") String reason, @Param("userId") Long userId,@Param("userName") String userName,@Param("date") String date);

	/**
	 * 查询币币交易记录
	 * @param userId
	 * @param start
	 * @param limit
	 * @param userName
	 * @param date
	 * @return
	 */
	public List<CoinChargeInfo> queryBackUserBbLog(@Param("userId") Long userId, @Param("start") Integer start, @Param("limit") Integer limit,@Param("userName") String userName,@Param("date") String date);

	public int queryBackUseriBbLogCount(@Param("userId") Long userId,@Param("userName") String userName,@Param("date") String date);


	public List<OutTradeNoLog> queryOutTradeNoLogDetail(@Param("userId") Long userId, @Param("start") Integer start, @Param("limit") Integer limit,@Param("name") String name,@Param("date") String date,@Param("type") String type);

	public int queryOutTradeNoLogDetailCount(@Param("userId") Long userId,@Param("name") String name,@Param("date") String date,@Param("type") String type);

	/**
	 * wecc总余额
	 * @return
	 */
	public Double queryNumCount();

	/**
	 * wecc总投资额
	 * @return
	 */
	public Double queryAmountCountType(@Param("date") String date,@Param("userId") Long userId,@Param("type") Integer type);

	/**
	 * wecc总投资额
	 * @return
	 */
	public Double queryAmountCount(@Param("date") String date,@Param("userId") Long userId);

	/**
	 * wecc总充值金额
	 * @return
	 */
	public Double queryRechargeCount(@Param("date") String date);

	/**
	 * wecc总充值人民币金额
	 * @return
	 */
	public int queryRechargeRmbCount(@Param("date") String date,@Param("userId") Long userId,@Param("userName") String userName);

	/**
	 * wecc总充值笔数
	 * @return
	 */
	public int queryRechargeCountAction(@Param("date") String date);

	/**
	 * wecc总币币充值金额
	 * @return
	 */
	public Double queryBbRechargeCount(@Param("date") String date);

	/**
	 * wecc币币交易笔数
	 * @return
	 */
	public int queryBbRechargeCountAction(@Param("date") String date);

	/**
	 * wecc总收益额
	 * @return
	 */
	public Double queryBonusCount(@Param("date") String date,@Param("userId") Long userId);

	/**
	 * wecc总收益额
	 * @return
	 */
	public Double queryBonusCountType(@Param("date") String date,@Param("userId") Long userId,@Param("type") Integer type);

	/**
	 * 总用户数
	 * @return
	 */
	public Integer queryPeopleNumCount();

	/**
	 * 漫画数量
	 * @return
	 */
	public Integer querycartoonNumCount();

	/**
	 * 小说数量
	 * @return
	 */
	public Integer queryNovelNumCount(@Param("type") Integer type);

	/**
	 * wecc已提总量
	 * @return
	 */
	public Double queryReated(@Param("date") String date,@Param("userId") Long userId);

	/**
	 * wecc未提总量
	 * @return
	 */
	public Double queryUnReated(@Param("date") String date,@Param("userId") Long userId);

	/**
	 * 查询非小号表中数据
	 *
	 * @param symbol
	 * @return
	 */
	public List<CurrencyChart> queryCurrencyChart(@Param("symbol") String symbol);

	@Select("select * from friendshare s where s.num > 0")
	public List<FriendShare> queryCleanFriendShareList();

	@Select("select -sum(c.num)*0.05 from casinolog c where c.num < 0")
	public double getCasinoPool();

	@Select("select * from usertickerlog l where l.reason = '竞猜提现到钱包'  order by id desc limit 10")
	public List<UserTickerLog> queryCasinoCashLog();

	@Select("select -ifnull(sum(l.num) ,0) from casinolog l where l.userId = #{arg0} and l.date = #{arg1} and l.num < 0")
	public double countTodayBet(Long userId, String date);

	@Select("select count(*) from casinoredpack l where l.userId = #{arg0} and l.date = #{arg1}")
	public int countTodayRedpack(Long userId, String date);

	@Select("select count(*) from casinoredpack l where l.userId = #{arg0}")
	public int countUserRedpack(Long userId);
}
